package mysql

import "gorm.io/gorm"

type MealProducts struct {
	gorm.Model
	MealProductsName      string  `gorm:"type:varchar(100);not null;comment:'餐品名称'"`
	MealProductsPrice     float64 `gorm:"type:double(10,2);not null;comment:'餐品价格'"`
	MealProductsScore     float64 `gorm:"type:double(10,2);not null;comment:'餐品评分'"`
	MealProductsInter     string  `gorm:"type:varchar(100);not null;comment:'餐品描述'"`
	MealProductsInventory int     `gorm:"type:int(20);not null;comment:'产品库存'"`
	MealProductsImage     string  `gorm:"type:varchar(255);not null;comment:'产品图片'"`
	MealProductsType      int     `gorm:"type:int(20);not null;comment:'1:堂食 2:外卖'"`
	MealProductsTypes     int     `gorm:"type:int(20);not null;comment:'1:精品推荐 2:人气热卖 3:精选套餐'"`
}

func MealProductsList(types int) (result []*MealProducts, err2 error) {
	DB.Debug().Where("meal_products_types = ?", types).Find(&result)
	return
}

func MealProductShow(id int) (result *MealProducts, err2 error) {
	DB.Debug().Where("id = ?", id).Limit(1).Find(&result)
	return
}

func InventoryUpdate(m map[string]string) error {
	return DB.Debug().Model(&MealProducts{}).Updates(m).Error

}
